<form class="form-horizontal padding-15">
    <div id="content_type">
        <ul class="nav nav-tabs v-nav-tabs" role="tablist" style="margin-left: 14px;margin-right: 14px;">
            <li role="presentation" class="active"><a href="#shop" aria-controls="shop" role="tab" data-toggle="tab" data-type="2"
                                       class="flex-auto-center">店铺首页</a></li>
            <li role="presentation"><a href="#detail" aria-controls="detail" role="tab" data-toggle="tab" data-type="3"
                                       class="flex-auto-center">商品详情页</a></li>
            <li role="presentation"><a href="#diy" aria-controls="diy" role="tab" data-toggle="tab" data-type="6"
                                       class="flex-auto-center">自定义页</a></li>
        </ul>
        <div class="template-list tab-content">
            <div class="tab-pane fade in active" id="shop">
                <ul class="template-list-ul clearfix">
                </ul>
            </div>
            <div class="tab-pane fade" id="detail">
                <ul class="template-list-ul clearfix">
                </ul>
            </div>
            <div class="tab-pane fade" id="diy">
                <ul class="template-list-ul clearfix">
                </ul>
            </div>
        </div>
    </div>
</form>
<script>
    require(['util'], function (util) {
        var system_template_list = {};
        $(function () {
            getSystemTemplateList();
            putSystemList();
        })

        function getSystemTemplateList() {
            $.ajax({
                type: "post",
                async: false,
                data: {},
                url: "{$mpSystemDefaultTemplateUrl}",
                success: function (data) {
                    system_template_list = data;
                }
            })
        }

        function putSystemList() {
            $.each(system_template_list, function (type, list) {
                var list_html = '';
                // 先加上空白模板
                list_html += '<li>';
                list_html += '<div class="template-list-pic"><img src="/public/static/images/customPC/blankTemplate.png" alt=""></div>';
                list_html += '<p class="template-list-title">空白模板</p>';
                list_html += '<p class="template-list-button"><a href="javascript:;" data-type="' + type + '" class="template-list-button-a J-create">立即创建</a></p>';
                list_html += '</li>';
                if (system_template_list[type]) {
                    $.each(list, function (k, v) {
                        list_html += '<li>';
                        list_html += '<div class="template-list-pic">';
                        list_html += '<img src=' + v.template_logo + ' alt="">';
                        list_html += '</div>';
                        list_html += '<p class="template-list-title">' + v.template_name + '</p>';
                        list_html += '<p class="template-list-button">';
                        list_html += '<a href="javascript:void(0);" data-type="' + type + '" data-id="' + v.id + '" class="template-list-button-a J-create">立即创建</a>';
                        list_html += '</p>';
                        list_html += '</li>'
                    })
                }

                var target = '#index ul';
                switch (type) {
                    case '2':
                        target = '#shop ul';
                        break;
                    case '3':
                        target = '#detail ul';
                        break;
                    case '4':
                        target = '#member ul';
                        break;
                    case '6':
                        target = '#diy ul';
                        break;
                }
                $(target).html(list_html);
            })
        }

        $('#content_type').on('click', '.J-create', function () {
            var type = $(this).attr('data-type');
            var id = $(this).attr('data-id');
            $.ajax({
                type: 'post',
                url: '{$createCustomTemplateUrl}',
                data: {
                    'type': type,
                    'id': id
                },
                success: function (res) {
                    if (res.code > 0) {
                        // util.message(res.message, 'success', __URL(PLATFORMMAIN + 'ADDONS_MAINminiProgramCustom&id=' + res.data.id));
                        window.location = __URL('ADDONS_ADMIN_MAINminiProgramCustom&id=' + res.data.id)
                    } else {
                        util.message(res.message, 'error');
                    }
                }
            });
        });
    });
</script>